<template>
    <div class="dv" id="allmap"></div>



</template>

<script>
    export default {
        name: 'Address',
        components: {

        },
        mounted() {
            // 获取位置信息
            this.getCity();
        },
        methods: {
            getCity() {
                var map = new BMap.Map("allmap");
                var point = new BMap.Point(116.331398,39.897445);
                map.centerAndZoom(point,12);
                map.enableScrollWheelZoom(true);     //开启鼠标滚轮缩放
                var geoc = new BMap.Geocoder();
                map.addEventListener("click", function(e){
                    var pt = e.point;
                    geoc.getLocation(pt, function(rs){
                        var addComp = rs.addressComponents;
                        alert(addComp.province + ", " + addComp.city + ", " + addComp.district + ", " + addComp.street + ", " + addComp.streetNumber);
                    });
                });
                function myFun(result){
                    var cityName = result.name;
                    map.setCenter(cityName);
                    alert("当前定位城市:"+cityName);

                }
                var myCity = new BMap.LocalCity();
                myCity.get(myFun);
            }
        }
    }
</script>

<style>
    .dv { width: 100%; height: 870px; }
</style>

